#有一个列表lst = [1,4,9,16,2,5,10,15]，生成一个新列表，要求新列表元素是lst相邻2项的和

# 1. 一次生成新列表，再填充
lst = [1,4,9,16,2,5,10,15]
length = len(lst)
newlength = length -1
newlist = [None] * newlength

for i in range(newlength):
    newlist[i] = lst[i] + lst[i+1]
print(newlist)

print('#' * 80)

# 2. 生成空列表，再追加
lst = [1,4,9,16,2,5,10,15]
length = len(lst)
newlist = []

for i in range(length-1):
    newlist.append(lst[i] + lst[i+1])
print(newlist)

print('#' * 80)

# 3. 列表解析式
lst = [1,4,9,16,2,5,10,15]
newlist = [lst[i] + lst[i+1] for i in range(len(lst)-1)]
print(newlist)


# 完成的不错
